//
//  HomeViewController.m
//  BaseFrame
//
//  Created by 孟学浩 on 2017/4/1.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "HomeViewController.h"
#import "ButWhatMapView.h"
#import "SearchViewController.h"
#import "RootMallView.h"
#import "RootLaundryView.h"

@interface HomeViewController ()

@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) UIView *headView;
@property (nonatomic,strong) NSArray *bannerArray;
@property (nonatomic,strong) NSMutableArray *dataArray;
Strong SDCycleScrollView *sdcView;
Strong UILabel *titleLabel;
Strong RootMallView *rootMallView;
Strong RootLaundryView *rootLaundryView;
Strong UIPageControl *pageControl;
Strong UILabel *messageLabel;

@end

//UI
@implementation HomeViewController

- (void)viewDidLoad {
    [super viewDidLoad];
//    [self getBanner];
    [[ButWhatMapView sharedInstanced]startUpdatingLocation:^{
        
    }];
    [self.view addSubview:self.tableView];
    UIButton *messageButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 44, 44)];
    [messageButton setImage:[UIImage imageNamed:@"root_message"] forState:UIControlStateNormal];
    [messageButton addTarget:self action:@selector(messageButton) forControlEvents:UIControlEventTouchUpInside];
    [messageButton addSubview:self.messageLabel];
    UIBarButtonItem * shieldButtonBarButton = [[UIBarButtonItem alloc] initWithCustomView:messageButton];
    self.navigationItem.rightBarButtonItems = @[shieldButtonBarButton];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"root_address"] style:0 target:self action:@selector(addressClick)];
//    badgeValue
    
    self.navigationItem.title = @"欢迎使用洗衣柜APP";
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}

#pragma mark - Event

- (void)messageButton{
   
}

- (void)addressClick{
    
}

#pragma mark - UIScrollViewDelegate

- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    //     NSLog(@"=============已经结束减速555555");
    self.pageControl.currentPage = scrollView.contentOffset.x/WIDTH_5S_SCALE;
}

#pragma mark - init

- (UILabel *)messageLabel{
    if (!_messageLabel) {
        _messageLabel  = [[UILabel alloc]initWithFrame:CGRectMake(27, 10, 10, 10)];
        _messageLabel.font = DEF_FontSize_8;
        _messageLabel.backgroundColor = getColor(@"ffffff");
        _messageLabel.textColor = getColor(mainColor);
        _messageLabel.layer.masksToBounds = YES;
        _messageLabel.layer.cornerRadius = 5;
        _messageLabel.text = @"2";
        _messageLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _messageLabel;
}

- (UIPageControl *)pageControl{
    if (!_pageControl) {
        _pageControl = [[UIPageControl alloc]initWithFrame:CGRectMake((SCREEN_WIDTH-100 / WIDTH_5S_SCALE)/2, self.headView.height - 30, 100 / WIDTH_5S_SCALE, 30)];
        //    pageControl.backgroundColor = [UIColor redColor];
        _pageControl.numberOfPages = 2;
        _pageControl.currentPage = 0;
        _pageControl.currentPageIndicatorTintColor = [UIColor redColor];
        _pageControl.pageIndicatorTintColor = [UIColor yellowColor];
    }
    return _pageControl;
}


- (RootMallView *)rootMallView{
    if (!_rootMallView) {
        _rootMallView = [[RootMallView alloc]initWithFrame:CGRectMake(0, 150 / WIDTH_5S_SCALE + 63  / WIDTH_5S_SCALE * 2 + 34 / WIDTH_5S_SCALE + 61 / WIDTH_5S_SCALE, SCREEN_WIDTH, 113 / WIDTH_5S_SCALE * 2)];
        _rootMallView.getRootMallClick = ^(NSInteger index) {
            NSLog(@"%ld",(long)index);
        };
        
    }
    return _rootMallView;
}

- (RootLaundryView *)rootLaundryView{
    if (!_rootLaundryView) {
        _rootLaundryView = [[RootLaundryView alloc]initWithFrame:CGRectMake(0, 150 / WIDTH_5S_SCALE, SCREEN_WIDTH, 63 / WIDTH_5S_SCALE * 2 + 34 / WIDTH_5S_SCALE)];
        _rootLaundryView.getRootLaundryClick = ^(NSInteger index) {
            NSLog(@"%ld",index);
        };
    }
    return _rootLaundryView;
}

- (SDCycleScrollView *)sdcView{
    if (!_sdcView) {
        _sdcView = [[SDCycleScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 150/WIDTH_5S_SCALE)];
        _sdcView.backgroundColor = getColor(mainColor);
        _sdcView.autoScrollTimeInterval = 3.0;
        _sdcView.backgroundColor = getColor(@"bfbfbf");
        _sdcView.pageControlDotSize = CGSizeMake(11, 11);
        _sdcView.pageControlAliment = SDCycleScrollViewPageContolAlimentCenter;
        _sdcView.currentPageDotImage = [UIImage imageNamed:@"homepage_banner_point"];
        _sdcView.pageDotImage = [UIImage imageNamed:@"homepage_banner_circle"];
        _sdcView.imageURLStringsGroup = @[@"004"];
        __block typeof(self) bSelf = self;
        _sdcView.clickItemOperationBlock = ^(NSInteger currentIndex) {
           
        };
        
    }
    return _sdcView;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel  = [[UILabel alloc]initWithFrame:CGRectMake(50 / WIDTH_5S_SCALE, 0, SCREEN_WIDTH - 30 / WIDTH_5S_SCALE - 50 / WIDTH_5S_SCALE, 46 / WIDTH_5S_SCALE)];
        _titleLabel.font = DEF_FontSize_14;
        _titleLabel.textColor = getColor(mainColor);
        _titleLabel.adjustsFontSizeToFitWidth = YES;
        _titleLabel.numberOfLines = 0;
        _titleLabel.text = @"您有一个快递包裹至二十一世纪大厦A座1917，取件码【554122】，请您尽快取件！";
    }
    return _titleLabel;
}


- (UIView *)headView{
    if (!_headView) {
        _headView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 150 / WIDTH_5S_SCALE + 63 / WIDTH_5S_SCALE * 2 + 34 / WIDTH_5S_SCALE + 61 / WIDTH_5S_SCALE + 113 / WIDTH_5S_SCALE * 2 + 34 / WIDTH_5S_SCALE + 30)];
        UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(15 / WIDTH_5S_SCALE, 150 / WIDTH_5S_SCALE + 63 / WIDTH_5S_SCALE * 2 + 34 / WIDTH_5S_SCALE + 7 / WIDTH_5S_SCALE, SCREEN_WIDTH - 30 / WIDTH_5S_SCALE,   46 / WIDTH_5S_SCALE)];
        bgView.layer.borderColor = getColor(mainColor).CGColor;
        bgView.layer.borderWidth = 1;
        bgView.layer.masksToBounds = YES;
        bgView.layer.cornerRadius = 23 / WIDTH_5S_SCALE;
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(5 / WIDTH_5S_SCALE, 0, 36 / WIDTH_5S_SCALE, 46 / WIDTH_5S_SCALE)];
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        imageView.image = [UIImage imageNamed:@"root_TheHorn"];
        [bgView addSubview:self.titleLabel];
        [bgView addSubview:imageView];
        UIView *lineView = [[UIView alloc]initWithFrame:CGRectMake(0, 63 / WIDTH_5S_SCALE * 2 + 34 / WIDTH_5S_SCALE + 150 / WIDTH_5S_SCALE, SCREEN_WIDTH, 0.5)];
        lineView.backgroundColor = getColor(dividerColor);
        
        UIView *line1View = [[UIView alloc]initWithFrame:CGRectMake(0, 63 / WIDTH_5S_SCALE * 2 + 34 / WIDTH_5S_SCALE + 150 / WIDTH_5S_SCALE + 61 / WIDTH_5S_SCALE, SCREEN_WIDTH, 0.5)];
        line1View.backgroundColor = getColor(dividerColor);
        
        [_headView sd_addSubviews:@[self.sdcView , self.rootLaundryView ,lineView , bgView , self.rootMallView , line1View , self.pageControl]];
    }
    return _headView;
}

- (UITableView *)tableView{
    if (!_tableView) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 49) style:UITableViewStyleGrouped];
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _tableView.sectionFooterHeight = .01;
        _tableView.sectionHeaderHeight = .01;
        _tableView.tableFooterView = [UIView new];
        _tableView.tableHeaderView = self.headView;
        _tableView.showsVerticalScrollIndicator = NO;
        _tableView.showsHorizontalScrollIndicator = NO;
        _tableView.backgroundColor = getColor(@"ffffff");
    }
    return _tableView;
}

@end
